package utils;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import lombok.Getter;
import lombok.Setter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.HashMap;

//全局的外部配置
public class FCExGlobalConfigUtil {
    private static FCExGlobalConfigUtil config;
    @Setter
    @Getter
    private double loadProportion = 1;//原始配置的分辨率比例，相对的
    @Setter
    @Getter
    private boolean showHelpTool = false;//显示helpScreen不
    @Setter
    @Getter
    private boolean playerActionInPloting = true;//剧情中自由移动不
    private HashMap<String, String> configMaps = new HashMap<>();

    static {
        config = new FCExGlobalConfigUtil();
    }

    public static FCExGlobalConfigUtil getIn() {
        return config;
    }

    public FCExGlobalConfigUtil() {
    }


    public void parseConfigFile() {
        try {
            File file = new File("./material/config/全局配置.xls");
            // 创建输入流，读取Excel
            InputStream is = new FileInputStream(file.getAbsolutePath());
            // jxl提供的Workbook类
            Workbook wb = Workbook.getWorkbook(is);
            Sheet sheet = wb.getSheet(0);
            // sheet.getRows()返回该页的总行数
            for (int i = 0; i < sheet.getRows(); i++) {
                String key = FCUIConfig.getCell(sheet, 0, i);
                String value = FCUIConfig.getCell(sheet, 1, i);
                if (key != null && value != null) {
                    configMaps.put(key, value);
                }
            }
            String data = configMaps.get("loadProportion");
            if (data != null) {
                loadProportion = Double.parseDouble(data);
            }
            data = configMaps.get("showHelpTool");
            if (data != null) {
                showHelpTool = Integer.parseInt(data) > 0;
            }
            data = configMaps.get("playerActionInPloting");
            if (data != null) {
                playerActionInPloting = Integer.parseInt(data) > 0;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (BiffException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
